import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/31 15:07
 * @description 优化2
 */
public class Solution3 {
    public static void main(String[] args) {

    }
    public int[] sumEvenAfterQueries(int[] nums, int[][] queries) {
        int n = nums.length;
        int sum = 0;
        for (int num: nums) {
            sum += num % 2 == 0 ? num : 0;
        }
        int[] ans = new int[queries.length];
        for (int i = 0; i < queries.length; i++) {
            int val = queries[i][0], index = queries[i][1];
            if (nums[index] % 2 == 0) {
                sum -= nums[index];
            }
            nums[index] += val;
            if (nums[index] % 2 == 0) {
                // 变化之后还是偶数，那么就加上贡献
                sum += nums[index];
            }
            ans[i] = sum;
        }
        return ans;
    }
}
